<template>
    <div>
    <header class="admin-container-header clearfix">
        <div class="float-left">
            <h4>密码修改</h4>
        </div>
    </header>
    <main class="admin-container-body" style="height: calc(100% - 50px)">
            <div class="row">
                <div class="col-md-6">
                    <section class="panel-box">
                        <section class="panel-box-body">
                            <i-form ref="form" :model="form" :label-width="100" :rules="rules">
                                <Form-item label="原密码" prop="oldPassword">
                                    <i-Input  type="password" v-model="form.oldPassword" placeholder="原密码"></i-Input>
                                </Form-item>
                                <Form-item label="新密码" prop="newPassword">
                                    <i-Input v-model="form.newPassword" type="password" placeholder="新密码"></i-Input>
                                </Form-item>
                                <Form-item label="确认密码" prop="rpassword">
                                    <i-Input v-model="form.rpassword" type="password" placeholder="确认密码"></i-Input>
                                </Form-item>
                                <Form-item >
                                    <i-Button type="primary" @click='passwordSave("form")'>保存</i-Button>
                                </Form-item>
                            </i-form>
                        </section>
                    </section>
                </div>
            </div>
        </main>
    </div>
</template>
<script>
export default {
    data () {
        return {
            itemName: '{$itemName}',
            form: {
                oldPassword: '',
                newPassword: '',
                rpassword: '',
            },
            rules: {
                oldPassword: [{
                        required: true,
                        message: '请输入密码',
                        trigger: 'blur'
                    },
                ],

                newPassword: [{
                        required: true,
                        message: '请输入新密码',
                        trigger: 'blur'
                    },
                ],

                rpassword: [{
                        required: true,
                        message: '请输入密码',
                        trigger: 'blur'
                    },
                ],
            },

           }
     },

    watch: {
    },

    mounted() {
    },

    methods: {
        passwordSave(formName) {
            this.$refs[formName].validate((valid) => {
                if(valid) {
                    this.$ssy.ajax('{$domain}/{$Think.config.admin}/ApiAdminAdmin/passwordEdit', {
                        oldPassword: md5(this.form.oldPassword),
                        newPassword: md5(this.form.newPassword),
                        rpassword: md5(this.form.rpassword),
                    }).then(res => {
                        if(res.code == 1) {
                            this.$Message.success('修改成功');
							location.href = '{$domain}/{$Think.config.admin}/login';
                        }
                    });
                } else {
                    return false;
                }
            });
        }
    }
}
</script>